package com.mopa.qzonegallery;
import java.util.ArrayList;
public class PostTask {
	public static ArrayList<String> taskArray=new ArrayList<String>();
	public static OnChooseListener onChooseListener;
	public static Boolean  isUpload=false;
	public interface OnChooseListener{
		void onStatusChange(String filePath,int which);
	}
	public static void setOnChooseListener(OnChooseListener listener)
	{
		onChooseListener=listener;
	}
	
	public synchronized static void setPost(Boolean upload)
	{
		isUpload=upload;
	}
	
	public synchronized static void addTask(String curTask,int which)
	{
		if(!taskArray.contains(curTask))
		{
			taskArray.add(curTask);
		}
		onChooseListener.onStatusChange(curTask,UpStatus.OnlyChoose);
	}
	public synchronized static String getTask()
	{
        if(taskArray.size()>0)
        {
        	onChooseListener.onStatusChange(taskArray.get(0),UpStatus.Posting);
        	return taskArray.get(0);
        }
		return null;
	}
	
	public synchronized static void removeTask(String curTask,int which)
	{
         taskArray.remove(curTask);
         onChooseListener.onStatusChange(curTask,UpStatus.Posted);
	}
	
	public synchronized static void failedTask(String curTask,int which)
	{
         onChooseListener.onStatusChange(curTask,UpStatus.PostFailed);
	}
	
	public synchronized static void clearAll()
	{
		taskArray.clear();
	}
	
	public synchronized static int getTaskNum()
	{
		return taskArray.size();
	}
	
	public synchronized static boolean cantais(String strItem)
	{
        if(taskArray.size()>0)
        {
        	if(taskArray.contains(strItem))
        	{
        		return true;
        	}
        }
		return false;
	}
}
